from django.shortcuts import render
from rest_framework.generics import ListAPIView,RetrieveAPIView
from .serializers import CourseCategoryModelSerializer,CourseModelSerialzier,CourseDetailModelSerializer,ChapterModelSerializer
from . import models
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.pagination import PageNumberPagination

class CourseCategoryView(ListAPIView):

    queryset = models.CourseCategory.objects.filter(is_show=True,is_deleted=False)
    serializer_class = CourseCategoryModelSerializer

class CustomPagenation(PageNumberPagination):
    page_size = 5
    page_query_param = 'page'
    page_size_query_param = 'size'
    max_page_size = 100

class CourseListView(ListAPIView):
    queryset = models.Course.objects.filter(is_show=True,is_deleted=False).order_by('id')
    serializer_class = CourseModelSerialzier
    filter_backends = [DjangoFilterBackend,]
    filter_fields = ('course_category',)
    pagination_class = CustomPagenation

class CourseDetailListView(RetrieveAPIView):
    queryset = models.Course.objects.filter(is_show=True,is_deleted=False)
    serializer_class = CourseDetailModelSerializer

class ChapterListView(ListAPIView):
    queryset = models.CourseChapter.objects.filter(is_show=True,is_deleted=False)
    serializer_class = ChapterModelSerializer
    filter_backends = [DjangoFilterBackend,]
    filter_fields = ('course',)















